<template>
  <div>
    <BasicTable @register="registerTable" size="small">
      <template #toolbar>
        <a-button preIcon="ant-design:plus-circle-outlined" type="primary"
          v-auth="'AssetsManagement.StoveManagement.Create'" @click="openCreateStoveModal">
          {{ t('common.createText') }}
        </a-button>
      </template>

      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
 
          <TableAction :actions="[
            {
              icon: 'clarity:note-edit-line',
              label: t('common.editText'),
              auth: 'AssetsManagement.StoveManagement.Update',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              label: t('common.delText'),
              auth: 'AssetsManagement.StoveManagement.Delete',
              popConfirm: {
                title: t('common.askDelete'),
                placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]" />
        </template>
      </template>
    </BasicTable>

    <CreateStove @register="registerCreateStoveModal" @reload="reload" :bodyStyle="{ 'padding-top': '0' }" />
    <UpdateStove @register="registerUpdateStoveModal" @reload="reload" :bodyStyle="{ 'padding-top': '0' }" />

  </div>
</template>
    
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicTable, TableAction, useTable } from '/@/components/Table';
import { tableColumns, searchFormSchema, getTableListAsync, deleteAsync } from '/@/views/asset/stove/Stove';
import { useI18n } from '/@/hooks/web/useI18n';
import { useModal } from '/@/components/Modal';
import CreateStove from './CreateStove.vue';
import UpdateStove from './UpdateStove.vue';

export default defineComponent({
  name: 'Stove',
  components: {
    BasicTable,
    TableAction,
    CreateStove,
    UpdateStove
  },
  setup() {
    const { t } = useI18n();
    const [registerCreateStoveModal, { openModal: openCreateStoveModal }] = useModal();
    const [registerUpdateStoveModal, { openModal: openUpdateStoveModal }] = useModal();

    const [registerTable, { reload }] = useTable({
      columns: tableColumns,
      formConfig: {
        labelWidth: 70,
        schemas: searchFormSchema,
      },
      api: getTableListAsync,
      showTableSetting: true,
      useSearchForm: true,
      bordered: true,
      canResize: true,
      showIndexColumn: true,
      immediate: true,
      scroll: { x: true },
      actionColumn: {
        width: 220,
        title: t('common.action'),
        dataIndex: 'action',
       // slots: { customRender: 'action' },
      },
    });

    function handleEdit(record: Recordable) {
      openUpdateStoveModal(true, {
        record: record,
      });
    }

    async function handleDelete(record: Recordable) {
      await deleteAsync({ id: record.id });
      await reload();
    }

    return {
      t,
      registerTable,
      reload,
      handleEdit,
      handleDelete,
      registerCreateStoveModal,
      registerUpdateStoveModal,
      openCreateStoveModal,
    };
  },
});
</script>
    